package dyyx;

import java.util.Properties;

import com.netflix.config.ConfigurationManager;

import feign.Feign;
import feign.RequestLine;
import feign.ribbon.RibbonClient;

public class FeignAndRibbonDemo {

	public static void main(final String[] args) {
		
		
		Properties properties = new Properties();
		
		properties.put("demo.ribbon.MaxAutoRetries","1");
		properties.put("demo.ribbon.OkToRetryOnAllOperations","true");
		properties.put("demo.ribbon.ServerListRefreshInterval","2000");
		properties.put("demo.ribbon.ConnectTimeout","2000");
		properties.put("demo.ribbon.ReadTimeout","3000");
		properties.put("demo.ribbon.listOfServers","localhost:8080,localhost:8090");
		properties.put("demo.ribbon.EnablePrimeConnections","true");

		// prefix demo ==> appName
	    // http://demo
		
		ConfigurationManager.loadProperties(properties);
		
		
		
		InfoService infoService = Feign.builder().client(RibbonClient.create())
				//.encoder(new JacksonEncoder())
				//.decoder(new JacksonDecoder())
				.target(InfoService.class,"http://demo");
		
		for(int i=0;i<100;i++) {
			long start = System.currentTimeMillis();
			String str = infoService.info();
			long end = System.currentTimeMillis();
            long time = end - start;
			System.out.println(str+" "+time);
		}
		


		
	}
	
	private static interface InfoService{
		@RequestLine("GET /info")
		String info();
	}



}
